import examples as ex


# testing for no error during execution
# (no verification of any kind)

"""
for i,liste in enumerate(ex.GDB_list) :
    for label in liste :
        G = getattr(ex, 'GDB_'+str(i)+'_'+label)()

        G.left_specials()
        G.right_specials()
        G.bispecials()

        for node in G.nodes():
            G.incoming_edges(node)
            G.outgoing_edges(node)
            G.is_left_special(node)
            G.is_right_special(node)
            G.is_bispecial(node)
            G.is_not_special(node)
            
        G.derive()
"""

for i,liste in enumerate(ex.GDB_test_list) :
    for label in liste :
        G = getattr(ex, 'GDB_'+label)()
        
        print label
        
        for n in G:
            print n
        
        print G.adj
        print G.adj.keys().sort()
        
            
        for n in G:
            print n

        print 'LS:'
        print G.left_specials()
        print 'RS:'
        print G.right_specials()
        print 'BS:'
        print G.bispecials()

        for node in G.nodes():
            G.incoming_edges(node)
            G.outgoing_edges(node)
            G.is_left_special(node)
            G.is_right_special(node)
            G.is_bispecial(node)
            G.is_not_special(node)
        
        print G
        print '* n-segments: *' 
        print G.nsegments()    
        print '* derivation: *'  
        GG = G.derive()
        print 'print out the derivative' 
        print GG
        print '-------------'
        #print GG.nsegments()
        print '-------------'
        #print GG.simplify()
        print '* do some choices in the derivative *'
        for ed in GG.mutable_edges_iter():
            print 'trying to remove ' + str(ed)
            res = GG.set_state(ed, 0)
            print 'resulted in ' + str(res)
            if res: break
        print '* altered derivative *'
        print GG
        print '* printing out regular paths in the altered derivative *'
        a = GG.regular_paths()
        for ed in a:
            print '==='
            for edd in ed:
                print edd      
        print '* simplification *'
        contracted_edges_dict = GG.simplify()
        print '-------------'
        print GG
        print '* let\'s begin the contraction *'
        print 'contractible edges are: '
        print GG.contractible_edges()
        print '* contraction length is *'
        con_len = GG.find_contraction_length()
        print con_len
        print '* contracting...'
        GG.execute_length_contraction(con_len)
        print GG
        print '* zero-simplification *'
        renamed_edges = GG.zero_simplification()
        print renamed_edges
        
        
        
        
        
        GG = GG.derive()
        print 'print out the derivative' 
        print GG
        print '-------------'
        #print GG.nsegments()
        print '-------------'
        #print GG.simplify()
        print '* do some choices in the derivative *'
        for ed in GG.mutable_edges_iter():
            print 'trying to remove ' + str(ed)
            res = GG.set_state(ed, 0)
            print 'resulted in ' + str(res)
            if res: break
        print '* altered derivative *'
        print GG
        print '* printing out regular paths in the altered derivative *'
        a = GG.regular_paths()
        for ed in a:
            print '==='
            for edd in ed:
                print edd      
        print '* simplification *'
        contracted_edges_dict = GG.simplify()
        print '-------------'
        print GG
        print '* let\'s begin the contraction *'
        print 'contractible edges are: '
        print GG.contractible_edges()
        print '* contraction length is *'
        con_len = GG.find_contraction_length()
        print con_len
        print '* contracting...'
        GG.execute_length_contraction(con_len)
        print GG
        print '* zero-simplification *'
        renamed_edges = GG.zero_simplification()
        print renamed_edges
        
        GG = GG.derive()
        print 'print out the derivative' 
        print GG
        print '-------------'
        #print GG.nsegments()
        print '-------------'
        #print GG.simplify()
        print '* do some choices in the derivative *'
        for ed in GG.mutable_edges_iter():
            print 'trying to remove ' + str(ed)
            res = GG.set_state(ed, 0)
            print 'resulted in ' + str(res)
            if res: break
        print '* altered derivative *'
        print GG
        print '* printing out regular paths in the altered derivative *'
        a = GG.regular_paths()
        for ed in a:
            print '==='
            for edd in ed:
                print edd      
        print '* simplification *'
        contracted_edges_dict = GG.simplify()
        print '-------------'
        print GG
        print '* let\'s begin the contraction *'
        print 'contractible edges are: '
        print GG.contractible_edges()
        print '* contraction length is *'
        con_len = GG.find_contraction_length()
        print con_len
        print '* contracting...'
        GG.execute_length_contraction(con_len)
        print GG
        print '* zero-simplification *'
        renamed_edges = GG.zero_simplification()
        print renamed_edges
        
        print ' '
        print GG.adj
        name_map = GG.automatic_vertex_rename()
        print GG.nodes()
        print GG.adj
        
        